package com.vmj.natives;

import com.vmj.natives.java.io.FileOutputStream;
import com.vmj.natives.java.lang.Class;
import com.vmj.natives.java.lang.ClassLoader;
import com.vmj.natives.java.lang.Double;
import com.vmj.natives.java.lang.Float;
import com.vmj.natives.java.lang.Object;
import com.vmj.natives.java.lang.String;
import com.vmj.natives.java.lang.System;
import com.vmj.natives.java.lang.Thread;
import com.vmj.natives.java.lang.Throwable;
import com.vmj.natives.java.security.AccessController;
import com.vmj.natives.java.util.concurrent.atomic.AtomicLong;
import com.vmj.natives.sun.misc.Signal;
import com.vmj.natives.sun.misc.Unsafe;
import com.vmj.natives.sun.misc.VM;
import com.vmj.natives.sun.reflect.NativeConstructorAccessorImpl;
import com.vmj.natives.sun.reflect.Reflaction;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by yangshoujun on 2017/9/16 上午12:32.
 */
public class Registry {

    public static final Map<java.lang.String, NativeMethod> nativeMethodMap = new HashMap<java.lang.String, NativeMethod>();

    static {
        Class.init();
        Object.init();
        System.init();
        Float.init();
        Double.init();
        String.init();
        VM.init();
        Unsafe.init();
        Reflaction.init();
        AccessController.init();
        Thread.init();
        Throwable.init();
        NativeConstructorAccessorImpl.init();
        AtomicLong.init();
        ClassLoader.init();

        Signal.init();
        FileOutputStream.init();
    }

    public static void register(java.lang.String className, java.lang.String methodName, java.lang.String methodDescripor, NativeMethod method) {
        java.lang.String key = className.concat("~").concat(methodName).concat("~").concat(methodDescripor);
        nativeMethodMap.put(key, method);
    }

    public static NativeMethod findNativeMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodDescripor) {
        if("()V".equals(methodDescripor)) {
            if("registerNatives".equals(methodName) || "initIDs".equals(methodName)) {
                return NativeMethod.EMPTY_METHOD;
            }
        }
        java.lang.String key = className.concat("~").concat(methodName).concat("~").concat(methodDescripor);
        return nativeMethodMap.get(key);
    }
}
